﻿using System;
using System.Drawing;
using System.Windows.Forms;
using static Utility.WinAPI;

namespace WallpaperEngine.Core
{
    public class WallpaperImg : WallpaperCore
    {
        public WallpaperImg(Wallpaper wallpaper) : base(wallpaper)
        {
            _wallpaper.Window = new Form
            {
                Height = _wallpaper.Fullscreen.Height,
                Width = _wallpaper.Fullscreen.Width,
                ShowInTaskbar = false,
                FormBorderStyle = FormBorderStyle.None,
            };
            _wallpaper.Window.Controls.Add(new PictureBox()
            {
                ImageLocation = PathManager.Fullpath,
                Left = 0,
                Top = 0,
                Height = _wallpaper.Fullscreen.Height,
                Width = _wallpaper.Fullscreen.Width,
                Dock = DockStyle.Fill,
                SizeMode = PictureBoxSizeMode.StretchImage
            });
            _wallpaper.Window.Show();
            SetParent(_wallpaper.Window.Handle, _wallpaper.Handle);
            SetWindowLong(_wallpaper.Window.Handle, WindowLongFlags.GWL_EXSTYLE, (int)WindowStylesEx.WS_EX_TOOLWINDOW | (int)WindowStylesEx.WS_EX_NOACTIVATE);//WS_EX_TOOLWINDOW=128
            SetWindowPos(_wallpaper.Window.Handle, IntPtr.Zero, 0, 0, _wallpaper.Fullscreen.Width, _wallpaper.Fullscreen.Height, SetWindowPosFlags.FrameChanged);
        }
    }
}